package com.example.bitemybatis.mapper;

import com.example.bitemybatis.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo")
    List<UserInfo> getUserInfo();


    //这里由于字段映射不上的时候得需要配置
    //当只有一个id值的时候，这个参数随便填都可以
    //有两个参数的时候，得需要进行给参数进行起别名
    @Results(id = "BaseResult",value = {
            @Result(column ="delete_flag",property = "deleteFlag"),
            @Result(column ="create_time",property = "createTime"),
            @Result(column ="update_time",property = "updateTime"),
    })
    @Select("select id,username,password,age,gender,phone,delete_flag,create_time,update_time from userinfo where id=#{id}")
    UserInfo getUserInfoById(Integer id);
    @ResultMap(value = "BaseResult")
    @Select("select * from userinfo where id = #{userId} and delete_flag = #{deleteFlag}")
    UserInfo queryUserInfoByDF(Integer userId, Integer deleteFlag);
    //插入
    @Insert("insert into userinfo(username,password,age,gender,phone) values(#{username},#{password},#{age},#{gender},#{phone})")
    Integer insertUserInfo(UserInfo userInfo);
    @Insert("insert into userinfo(username,password,age,gender,phone) values(#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender},#{userInfo.phone})")
    Integer insertUserInfo1(@Param("userInfo") UserInfo userInfo);
}
